/**
 * Created by Administrator on 2017/5/17.
 */
$(function(){
    cameraList();
    index0();
});


var index0oneInterval;
var index0fiveInterval;
var index010secInterval;
function index0() {

    index0one();
    index0five();
    checkEmptycw();
    //0

    clearInterval(index0oneInterval);
    clearInterval(index0fiveInterval);
    clearInterval(index010secInterval);

    index0oneInterval=setInterval(index0one,60000);
    index0fiveInterval=setInterval(index0five,300000);
    index010secInterval = setInterval(checkEmptycw,60000);

    initPlugin();

}

/****************第一标签方法开始*************************/

//1分钟定时任务
function index0one() {
    cllCount();
    kllTodayCount();
    xsTodayCount();
    queryParkingSpace();
}
//5分钟定时任务
function index0five() {
    cllChart(0);
    //dpSailChart();
    //sailChart(0);
    //nbSailChart(0);
    kllChart(0);
    //=============借的echarts
    carFlowChart();
    carGroupChart();
    ckllCount();
    carfrom();
    //==================结束
}

//查询厕所剩余坑位 111
function checkEmptycw(){
    $.get(baseURL + "gc/statoiletseat/checkEmptycw", function(r){
        $("#nanS").html(19-Number(r.data.southMaleUsed));
        $("#nanN").html(19-Number(r.data.northMaleUsed));
        $("#nvS").html(48-Number(r.data.southFemaleUsed));
        $("#nvN").html(48-Number(r.data.northFemaleUsed));
    });
}
//查询空余车位，左上角表格 111
function queryParkingSpace(){
    $.get(baseURL + "cw/cwparkingspace/spaceCount", function(r){
        $("#pz").html(r.p);
        $("#pk").html(r.pk);
        $("#psk").html(r.psk);
        $("#pnk").html(r.pnk);
    });
}
//今日车流量统计 111
function cllCount(){
    $.get(baseURL + "cll/cllvehiclerecord/cllCount", function(r){
        var cllCount= r.cllCount;
        var j=0;
        for (let i = 0; i <=5 ; i++) {
            $('#cll'+i).text(0);
        }
        for (var i = cllCount.length-1; i >=0 ; i--) {
            $('#cll'+j).text(cllCount[i]);
            j++;
        }
    });
}

//今日客流量统计 111
function kllTodayCount(){
    $.get(baseURL + "rll/rlldayinfo/kllCount", function(r){
        var kllCount= r.kllCount;
        var j=0;
        for (let i = 0; i <=5 ; i++) {
            $('#kll'+i).text(0);
        }
        for (var i = kllCount.length-1; i >=0 ; i--) {
            $('#kll'+j).text(kllCount[i]);
            j++;
        }
    });
}

//今日销售量统计/销售额统计 111
function xsTodayCount(){
    $.get(baseURL + "jxc/jxcsaleorder/xsTodayCount", function(r){
        var xslTodayCount= r.xslTodayCount;
        var xseTodayCount= r.xseTodayCount;
        var j=0;
        for (var i = xslTodayCount.length-1; i >=0 ; i--) {
            $('#xsl'+j).text(xslTodayCount[i]);
            j++;
        }
        j=0;
        for (var i = xseTodayCount.length-1; i >=0 ; i--) {
            $('#xse'+j).text(xseTodayCount[i]);
            j++;
        }
    });
}

//今日车流量曲线 111
function cllChart(type) {
    $.get( "../../cll/cllvehiclerecord/cllChart/"+type,function(r){
        $("#scount").html("南区:"+r.southList[2]+"车次");
        $("#ncount").html("北区:"+r.northList[2]+"车次");
        var myChart = echarts.init(document.getElementById('cllChart'));
        var option = {
            tooltip : {
                trigger: 'axis',
                formatter: function(params) { //自定义函数修改折线图给数据加单位
                    var str = '';//声明一个变量用来存储数据
                    str += '<div>'+ params[0].name +'</div>'; //显示首行的函数
                    for(var i=0; i<params.length; i++) { //图显示的数据较多时需要循环数据，这样才可以成功的给多条数据添加单位
                        str += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'+params[i].color+';"></span>'+ params[i].seriesName +'</span> : <span>'+ params[i].data+'车次' +'</br>';
                    }
                    return str;
                }
            },
            grid: {
                x: 46,
                y:30,
                x2:32,
                y2:30,
                borderWidth: 0
            },
            legend: {
                data:['南区','北区'],
                textStyle:{
                    color:"#e9ebee"
                },
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    name:'小时',
                    boundaryGap : false,
                    data : r.southList[0],
                    splitLine: {
                        show: false
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#a4a7ab'
                        }
                    }
                }
            ],
            yAxis : [
                {
                    type : 'value',
                    name:'总数/车次',
                    splitLine: {
                        show: false
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#a4a7ab'
                        }
                    }

                }
            ],
            series : [
                {
                    name:'南区',
                    type:'line',
                    //stack: '车次',
                    data:r.southList[1],
                    smooth: true,
                    itemStyle: {
                        normal: {
                            color:"#e15828"
                        }
                    }
                },
                {
                    name:'北区',
                    type:'line',
                    //stack: '车次',
                    smooth: true,
                    data:r.northList[1],
                    itemStyle: {
                        normal: {
                            color:"#2e7cff"
                        }
                    }
                }
            ]
        };
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    })
}
//24小时客流量曲线 111
function kllChart(type) {

    $.get( "../../rll/rllhourcount/kllChart1/"+type,function(r){

        $("#skllCount").html("南区:"+r.southList[2]+"人次");
        $("#nkllCount").html("北区:"+r.northList[2]+"人次");
        var myChart = echarts.init(document.getElementById('kllChart'));
        var option = {
            tooltip : {
                trigger: 'axis',
                formatter: function(params) { //自定义函数修改折线图给数据加单位
                    var str = '';//声明一个变量用来存储数据
                    str += '<div>'+ params[0].name +'</div>'; //显示首行的函数
                    for(var i=0; i<params.length; i++) { //图显示的数据较多时需要循环数据，这样才可以成功的给多条数据添加单位
                        str += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'+params[i].color+';"></span>'+ params[i].seriesName +'</span> : <span>'+ params[i].data+'人次' +'</br>';
                    }
                    return str;
                }
            },
            grid: {
                x: 46,
                y:30,
                x2:32,
                y2:30,
                borderWidth: 0
            },
            legend: {
                data:['南区','北区'],
                textStyle:{
                    color:"#e9ebee"
                },
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    name:'小时',
                    boundaryGap : false,
                    data : r.southList[0],
                    splitLine: {
                        show: false
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#a4a7ab'
                        }
                    }
                }
            ],
            yAxis : [
                {
                    type : 'value',
                    name:'客流/人次',
                    splitLine: {
                        show: false
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#a4a7ab'
                        }
                    }

                }
            ],
            series : [
                {
                    name:'南区',
                    type:'line',
                    //stack: '人次',
                    data:r.southList[1],
                    smooth: true,
                    itemStyle: {
                        normal: {
                            color:"#e15828"
                        }
                    }
                },
                {
                    name:'北区',
                    type:'line',
                    //stack: '人次',
                    smooth: true,
                    data:r.northList[1],
                    itemStyle: {
                        normal: {
                            color:"#2e7cff"
                        }
                    }
                }
            ]
        };
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    })
}
//24小时单品销量排行 111
function dpSailChart(){
    var detailName=[];
    var detaiAmount=[];
    $.get( "../../jxc/jxcselldetails/detailsRanking",function(r){

        for (var i = r.detailsRanking.length-1; i >=0; i--) {
            detailName.push(r.detailsRanking[i].yvalue);
            detaiAmount.push(r.detailsRanking[i].xvalue);
        }
        var myChart = echarts.init($("#dpSailChart")[0]);
        var option = {
            tooltip : {
                trigger: 'axis',
                formatter: function(params) { //自定义函数修改折线图给数据加单位
                    var str = '';//声明一个变量用来存储数据
                    str += '<div>'+ params[0].name +'</div>'; //显示首行的函数
                    for(var i=0; i<params.length; i++) { //图显示的数据较多时需要循环数据，这样才可以成功的给多条数据添加单位
                        str += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'+params[i].color+';"></span>'+ params[i].seriesName +'</span> : <span>'+ params[i].data+'份' +'</br>';
                    }
                    return str;
                },
                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            grid: {
                x: 90,
                y:30,
                x2:32,
                y2:40,
                borderWidth: 0
            },
            xAxis:  {
                type: 'value',
                name:'销量/个',
                x:'180',
                splitLine: {
                    show: false
                },
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#a4a7ab'
                    }
                }
            },
            yAxis: {
                type: 'category',
                name:'商品名',
                data: detailName,
                splitLine: {
                    show: false
                },
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#a4a7ab'
                    }
                }
            },
            series: [
                {
                    name: '销售数量',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            show: true,
                            position: 'insideRight'
                        }
                    },
                    data: detaiAmount,
                    itemStyle: {
                        normal: {
                            color:"#ff7d0a"
                        }
                    }
                }
            ]
        };
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    })
}
//今日销售趋势 111
function sailChart(type){
    var name=[];
    var sousale=[];
    var norsale=[];
    var smakmax=null;//南区最大值
    var smaksmall=null;//南区最小值
    var smakmaxx=null;//南区最大值x轴
    var smaksmallx=null;//南区最小值x轴
    var smakmaxy=null;//南区最大值y轴
    var smaksmally=null;//南区最小值y轴
    var nmakmax=null;//北区最大值
    var nmaksmall=null;//北区最小值
    var nmakmaxx=null;//北区最大值x轴
    var nmaksmallx=null;//北区最小值x轴
    var nmakmaxy=null;//北区最大值y轴
    var nmaksmally=null;//北区最小值y轴
    $.get( "../../jxc/jxcsaleorder/hourTodaysale/"+type,function(r){

        smakmax=r.southsale[0].yvue.toFixed(2);
        smaksmall=r.southsale[0].yvue.toFixed(2);
        smakmaxx=r.southsale[0].name;
        smakmaxy=r.southsale[0].yvue.toFixed(2);
        smaksmallx=r.southsale[0].name;
        smaksmally=r.southsale[0].yvue.toFixed(2);

        nmakmax=r.northsale[0].yvue.toFixed(2);
        nmaksmall=r.northsale[0].yvue.toFixed(2);
        nmakmaxx=r.northsale[0].name;
        nmakmaxy=r.northsale[0].yvue.toFixed(2);
        nmaksmallx=r.northsale[0].name;
        nmaksmally=r.northsale[0].yvue.toFixed(2);
        for (var i = r.southsale.length-1; i >=0 ; i--) {
            name.push(r.southsale[i].name+":00");
            sousale.push(r.southsale[i].yvue.toFixed(2));
            if(r.southsale[i].yvue>=smakmax){
                smakmax=r.southsale[i].yvue.toFixed(2);
                smakmaxx=r.southsale[i].name+":00";
                smakmaxy=r.southsale[i].yvue.toFixed(2);
            }else if(r.southsale[i].yvue<=smaksmall){
                smaksmall=r.southsale[i].yvue.toFixed(2);
                smaksmallx=r.southsale[i].name+":00";
                smaksmally=r.southsale[i].yvue.toFixed(2);
            }
        }
        for (var i = r.northsale.length-1; i >=0; i--) {
            norsale.push(r.northsale[i].yvue.toFixed(2));
            if(r.northsale[i].yvue>=nmakmax){
                nmakmax=r.northsale[i].yvue.toFixed(2);
                nmakmaxx=r.northsale[i].name+":00";
                nmakmaxy=r.northsale[i].yvue.toFixed(2);
            }else if(r.northsale[i].yvue<=nmaksmall){
                nmaksmall=r.northsale[i].yvue.toFixed(2);
                nmaksmallx=r.northsale[i].name+":00";
                nmaksmally=r.northsale[i].yvue.toFixed(2);
            }
        }
        var myChart = echarts.init($("#sailChart")[0]);
        option = {
            title : {
                text: '',
                textStyle:{
                    color:"#e9ebee"
                },
                x:'center'
            },
            tooltip : {
                trigger: 'axis',
                formatter: function(params) { //自定义函数修改折线图给数据加单位
                    var str = '';//声明一个变量用来存储数据
                    str += '<div>'+ params[0].name +'</div>'; //显示首行的函数
                    for(var i=0; i<params.length; i++) { //图显示的数据较多时需要循环数据，这样才可以成功的给多条数据添加单位
                        str += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'+params[i].color+';"></span>'+ params[i].seriesName +'</span> : <span>'+ params[i].data+'元' +'</br>';
                    }
                    return str;
                }
            },
            legend: {
                orient : 'vertical',
                x : 'left',
                data:['南区','北区'],
                textStyle:{
                    color:"#e9ebee"

                },
            },

            calculable : false,
            xAxis : [
                {
                    type : 'category',
                    name:'小时',
                    splitLine:{show: false},
                    axisLabel : {
                        formatter: '{value} ',
                        textStyle: {
                            color: '#a4a7ab',
                            align: 'right'
                        }
                    },
                    data : name,
                }
            ],
            yAxis : [
                {
                    type : 'value',
                    name:'销售额/元',
                    splitLine:{show: false},
                    axisLabel : {
                        formatter: '{value} ',
                        textStyle: {
                            color: '#a4a7ab',
                            align: 'right'
                        }
                    }
                }
            ],
            grid:{
                borderWidth:0
            },
            series : [
                {
                    name:'南区',
                    type:'bar',
                    data:sousale,
                    itemStyle: {
                        normal: {
                            color: '#2481ff'
                        }
                    },
                    markPoint : {
                        data : [
                            {name : '最高', value : smakmax, xAxis: smakmaxx, yAxis: smakmaxy, symbolSize:18},
                            {name : '最低', value : smaksmall, xAxis: smaksmallx, yAxis: smaksmally}
                        ]
                    },
                    markLine : {
                        data : [
                            {type : 'average', name: '平均值'}
                        ]
                    }
                },
                {
                    name:'北区',
                    type:'bar',
                    data:norsale,
                    itemStyle: {
                        normal: {
                            color: '#1afffd'
                        }
                    },

                    markPoint : {
                        data : [
                            {name : '最高', value : nmakmax, xAxis: nmakmaxx, yAxis: nmakmaxy, symbolSize:18},
                            {name : '最低', value : nmaksmall, xAxis: nmaksmallx, yAxis: nmaksmally}
                        ]
                    },
                    markLine : {
                        data : [
                            {type : 'average', name : '平均值'}
                        ]
                    }
                }
            ]
        };
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    })
}


//24小时南区北区销售统计 111
function nbSailChart(type){
    //南区销量
    $(function () {
        //var southName = [];
        //var northName = [];
        var southValue = [];
        var northValue = [];
        var clor = ['#1afffd', '#2e7cff', '#ffcb89', '#005ea1', '#0ad5ff','#990099','#FF0000','#009900','#FF00FF','#FFC0CB','#B0C4DE','#C0C0C0','#8B4513','#FFE4B5','#808000','#7CFC00','#40E0D0','#BA55D3','#F0FFFF','#E6E6FA','#5F9EA0'];
        $.get("../../jxc/jxcsaleorder/hourTodaySalesvolume/"+type, function (r) {
            var southList=r.southvolume;
            var northList=r.northvolume;
            for (let i = 0; i < southList.length; i++) {
                southValue.push({
                    value: (southList[i].totalAmount).toFixed(2), name: southList[i].shopName, itemStyle: {
                        /* normal: {
                             color: clor[i]
                         }*/
                    }
                });
            }
            for (let i = 0; i < northList.length; i++) {
                northValue.push({
                    value: (northList[i].totalAmount).toFixed(2), name: northList[i].shopName, itemStyle: {
                        /* normal: {
                             color: clor[i]
                         }*/
                    }
                });
            }
            var myChart = echarts.init($("#nqSailChart")[0]);
            option = {
                tooltip : {
                    trigger: 'item',
                    formatter: "{a}<br/>{b}:{c}"+"元"+"({d}%)",
                    position: [40, 150]
                },
                title: {
                    text: '南区',
                    textStyle: {
                        color: "#e9ebee"

                    },
                    x: 'center'

                },
                calculable: false,
                series: [
                    {
                        name: '销售额',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: southValue
                    }
                ]
            };
            myChart.setOption(option);
            window.addEventListener("resize",function(){
                myChart.resize();
            });
            var myChart1 = echarts.init($("#bqSailChart")[0]);
            option = {
                tooltip : {
                    trigger: 'item',
                    formatter: "{a}<br/>{b}:{c}"+"元"+"({d}%)",
                    position: [40, 150]
                },
                title: {
                    text: '北区',
                    textStyle: {
                        color: "#e9ebee"

                    },
                    x: 'center'

                },
                calculable: false,
                series: [
                    {
                        name: '销售额',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: northValue
                    }
                ]
            };
            myChart1.setOption(option);
            window.addEventListener("resize",function(){
                myChart1.resize();
            });
        });
    });
}
var s_setting = {
    /*view: {
        fontCss : {color:"white"},
    },*/
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url:"nourl"
        }
    },
    /* check: {
         enable: true ,//显示复选框
         chkStyle : "radio"
     },*/
    callback:{
        onClick: click// 点击事件回调函数
    }
};
var s_ztree;
var n_setting = {
    /* view: {
         fontCss : {color:"white"},
     },*/
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url:"nourl"
        }
    },
    /* check: {
         enable: true ,//显示复选框
         chkStyle : "radio"
     },*/
    callback:{
        onClick: click// 点击事件回调函数
    }
};
var n_ztree;
function click(event, treeId, treeNode){
    if(treeNode.isClick){
        $("#cName").html("当前监控点："+treeNode.name);
        $("#cName").attr("name",treeNode.data);
        $("#errMessage").text("");
        if(playMode==0){
            startPreview(treeNode.data,-1);
        }

    }
};
var southlist=[];
var northlist=[];
function cameraList(){
    $.ajax.async=false;
    $.get( "../../jk/jkcamara/northSouthCamara",function(r){
        var south= r.southCamaraTree;//南区
        var north= r.northCamaraTree;//北区
        n_ztree = $.fn.zTree.init($("#northTree"), n_setting,north);
        s_ztree = $.fn.zTree.init($("#southTree"), s_setting,south);
        var n_nodes=n_ztree.transformToArray(n_ztree.getNodes());
        for(var i=0;i<n_nodes.length;i++){
            if(n_nodes[i].level==0){
                n_ztree.expandNode(n_nodes[i], true, true, true);
            }else{
                n_ztree.expandNode(n_nodes[i], false, true, true);
            }
        }
        var s_nodes=s_ztree.transformToArray(s_ztree.getNodes());
        for(var i=0;i<s_nodes.length;i++){
            if(s_nodes[i].level==0){
                s_ztree.expandNode(s_nodes[i], true, true, true);
            }else{
                s_ztree.expandNode(s_nodes[i], false, true, true);
            }
        }
        var sinfo="";
        var ninfo="";
        var count=0;
        var count1=0;
        for(var i=0;i<south.length;i++){
            if(count<4){
                if(south[i].isClick){
                    southlist.push(south[i]);
                    sinfo +="<span name="+south[i].data+" onclick='startCamara(this)' class='year_chose camaraRow1'>"+south[i].name+"</span>";
                    count ++;
                }
            }else if(count<7){
                if(south[i].isClick){
                    southlist.push(south[i]);
                    sinfo +="<span name="+south[i].data+" onclick='startCamara(this)' class='year_chose camaraRow2'>"+south[i].name+"</span>";
                    count ++;
                }
            }
        }
        sinfo +="<span name='sou' onclick='morethan(this)' class='year_chose camaraRow2'>更多</span>"
        $("#south").append(sinfo);
        for(var i=0;i<north.length;i++){
            if(count1<4){
                if(north[i].isClick){
                    northlist.push(north[i])
                    ninfo +="<span name="+north[i].data+" onclick='startCamara(this)' class='year_chose camaraRow1'>"+north[i].name+"</span>";
                    count1 ++;
                }
            }else if(count1<7){
                if(north[i].isClick){
                    northlist.push(north[i])
                    ninfo +="<span name="+north[i].data+" onclick='startCamara(this)' class='year_chose camaraRow2'>"+north[i].name+"</span>";
                    count1 ++;
                }
            }
        }
        ninfo +="<span name='nor' onclick='morethan(this)' class='year_chose camaraRow2'>更多</span>"
        $("#north").append(ninfo);
    })
    $.ajax.async=true;
}

function morethan(data){
    var name=$(data).attr("name");
    if(name =="sou"){
        layer.open({
            type: 1,
            offset: ['270px','1350px'],
            skin: 'layui-layer-molv',
            title: "南区监控列表",
            area: ['300px', '450px'],
            shade: 0,
            shadeClose: false,
            content: jQuery("#southLayer"),
            btn: ['确定', '取消'],
            btn1: function (index) {
                var checkedNodes=s_ztree.getSelectedNodes();//所选择节点
                if(checkedNodes[0].isClick){
                    //console.log(checkedNodes[0].data+"------------点击后----------")
                    startPreview(checkedNodes[0].data,-1);
                }
                layer.close(index);
            }
        })
    }else if(name =="nor"){
        layer.open({
            type: 1,
            offset: ['270px','1350px'],
            skin: 'layui-layer-molv',
            title: "北区监控列表",
            area: ['300px', '450px'],
            shade: 0,
            shadeClose: false,
            content: jQuery("#northLayer"),
            btn: ['确定', '取消'],
            btn1: function (index) {
                var checkedNodes=n_ztree.getSelectedNodes();//所选择节点
                if(checkedNodes[0].isClick){
                    startPreview(checkedNodes[0].data,-1);
                }
                layer.close(index);
            }
        })
    }
}
function startPreview(cameraIndexCode,wndId){
    var streamMode = 0;                                     //主子码流标识：0-主码流，1-子码流
    var transMode = 1;                                      //传输协议：0-UDP，1-TCP
    var gpuMode = 0;                                        //是否启用GPU硬解，0-不启用，1-启用
    cameraIndexCode = cameraIndexCode.replace(/(^\s*)/g, "");
    cameraIndexCode = cameraIndexCode.replace(/(\s*$)/g, "");
    oWebControl.JS_RequestInterface({
        funcName: "startPreview",
        argument: JSON.stringify({
            cameraIndexCode:cameraIndexCode,                //监控点编号
            streamMode: streamMode,                         //主子码流标识
            transMode: transMode,                           //传输协议
            gpuMode: gpuMode,                               //是否开启GPU硬解
            wndId:wndId                                     //可指定播放窗口
        })
    })
}

//视频插件加载完后运行的方法
function videoLoad() {
    if(southlist.length>1){
        startPreview(southlist[0].data,1);
        startPreview(southlist[1].data,2);
    }
    if(northlist.length>1){
        startPreview(northlist[0].data,3);
        startPreview(northlist[1].data,4);
    }
}

function startCamara(data){
    var camaraIndexCode=$(data).attr("name");
    startPreview(camaraIndexCode,-1);
}

/****************第一标签方法结束*************************/




//==================借用的echarts
var zytype = 0;
var zytime="";
//车流量统计
function carFlowChart() {
    var xname=null;
    if(zytype == "0"){
        xname="小时";
    }else if(zytype == "1"){
        xname="日期";
    }
    $.get("../../cll/cllvehiclerecord/carflow?type="+zytype+"&time="+zytime, function (r) {
        /*console.log(1)
        console.log(r)*/
        souinvalue=r.southinlist;
        sououtvalue=r.southoutlist;
        norinvalue=r.northlist;
        noroutvalue=r.northoutlist;
        var myChart = echarts.init($("#carFlowChart")[0]);
        var option = {
            tooltip : {
                trigger: 'axis',
                formatter: function(params) { //自定义函数修改折线图给数据加单位
                    var str = '';//声明一个变量用来存储数据
                    str += '<div>'+ params[0].name +'</div>'; //显示首行的函数
                    for(var i=0; i<params.length; i++) { //图显示的数据较多时需要循环数据，这样才可以成功的给多条数据添加单位
                        str += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'+params[i].color+';"></span>'+ params[i].seriesName +'</span> : <span>'+ params[i].data+'车次' +'</br>';
                    }
                    return str;
                }
            },
            legend: {
                x: 'center',
                data: ["南区入口","南区出口","北区入口","北区出口"],
                textStyle:{
                    color:"#e9ebee"
                }
            },
            grid: {
                x: 46,
                y:30,
                x2:32,
                y2:40,
                borderWidth: 0
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    name:xname,
                    boundaryGap : false,
                    data :r.southinlist[0],
                    splitLine: {
                        show: false
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#a4a7ab'
                        }
                    }
                }
            ],
            yAxis : [
                {
                    type : 'value',
                    name :"总数/车次",
                    splitLine: {
                        show: false
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#a4a7ab'
                        }
                    }

                }
            ],
            series : [
                {
                    name:"南区入口",
                    type:'line',
                    //stack: '辆',
                    data:r.southinlist[1],
                    smooth: true,
                    itemStyle: {
                        normal: {
                            //color:"#45c0ff"
                            color:"red"
                        }
                    }
                },
                {
                    name:"南区出口",
                    type:'line',
                    //stack: '辆',
                    data:r.southoutlist[1],
                    smooth: true,
                    itemStyle: {
                        normal: {
                            color:"#0ad5ff"
                        }
                    }
                },
                {
                    name:"北区入口",
                    type:'line',
                    //stack: '辆',
                    data:r.northlist[1],
                    smooth: true,
                    itemStyle: {
                        normal: {
                            color:"#005ea1"
                        }
                    }
                },
                {
                    name:"北区出口",
                    type:'line',
                    //stack: '辆',
                    data:r.northoutlist[1],
                    smooth: true,
                    itemStyle: {
                        normal: {
                            color:"#ffcb89"
                        }
                    }
                }
            ]
        };
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    })
}
function carGroupChart() {
    var clor = ['#1afffd', '#2e7cff', '#ffcb89', '#005ea1', '#0ad5ff','#990099','#FF0000','#009900','#FF00FF','#FFC0CB','#B0C4DE','#C0C0C0','#8B4513','#FFE4B5','#808000','#7CFC00','#40E0D0','#BA55D3','#F0FFFF','#E6E6FA','#5F9EA0'];
    var type=24;
    // var cartype=[];
    var carvalue=[];
    $.get("../../cll/cllvehiclerecord/cartype?type="+zytype+"&time="+zytime, function (r) {
        var list=r.cartypelist;
        for (var i = 0; i <list.length ; i++) {
            //cartype.push(list[i].areaname);
            carvalue.push({
                value:list[i].yvalie,name:list[i].areaname,itemStyle:{
                    normal:{
                        color:clor[i]
                    }
                }
            });
        }
        var myChart = echarts.init($("#carGroupChart")[0]);
        var option = {
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c}"+"车次"+" ({d}%)",
                position: [70, 280]
            },
            /*legend: {
                x: 'center',
                y:"16",
                data:cartype,
                textStyle:{
                    color:"#e9ebee"
                }
            },*/
            series : [
                {
                    itemStyle: {
                        normal: {
                            label: {
                                show: false
                            },
                            labelLine: {
                                show: false
                            }
                        }
                    },
                    name: '',
                    type: 'pie',
                    radius : '50%',
                    center: ['53%', '60%'],
                    data:carvalue,
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    });
}
function ckllCount() {
    /*$.get(baseURL + "cll/cllvehiclerecord/cllCount?type="+zytype+"&time="+zytime, function(r){
        var cllCount= r.cllCount;
        $("#cllz").html(cllCount+"车次")
        $("#clln").html(r.southCount+"车次")
        $("#cllb").html(r.northCount+"车次")
    })*/
    $.get(baseURL + "rll/rlldayinfo/kllCount?type="+zytype+"&time="+zytime, function(r){
        var kllCount= r.kllCount;
        /* $("#kllz").html(kllCount+"人次")
         $("#klln").html(r.southCount+"人次")
         $("#kllb").html(r.northCount+"人次")
 */
        var area=["南区","北区"];
        var value=[{value:r.southCount,name:"南区"},{value:r.northCount,name:"北区"}];

        var myChart = echarts.init(document.getElementById('peoplecount'));
        var option = {
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c}"+"人次"+" ({d}%)",
                position: [65, 280]
            },
            legend: {
                x: 'center',
                y: 16,
                data:area,
                textStyle:{
                    color:"#e9ebee"
                }
            },
            series : [
                {
                    name: '客流统计',
                    type: 'pie',
                    radius : '50%',
                    center: ['50%', '60%'],
                    data:value,
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    });
}
//车辆归属地统计
function carfrom() {
    var areaname=[];
    var areavalue=[];
    $.get("../../cll/cllvehiclerecord/carownership?type="+zytype+"&time="+zytime, function (r) {
        for (var i = 0; i <r.carownership.length ; i++) {
            areaname.push(r.carownership[i].areaname);
            areavalue.push(r.carownership[i].yvalie);
        }
        var myChart = echarts.init($("#carfrom")[0]);
        var option = {
            tooltip : {
                trigger: 'axis',
                formatter: function(params) { //自定义函数修改折线图给数据加单位
                    var str = '';//声明一个变量用来存储数据
                    str += '<div>'+ params[0].name +'</div>'; //显示首行的函数
                    for(var i=0; i<params.length; i++) { //图显示的数据较多时需要循环数据，这样才可以成功的给多条数据添加单位
                        str += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'+params[i].color+';"></span>'+ params[i].seriesName +'</span> : <span>'+ params[i].data+'辆' +'</br>';
                    }
                    return str;
                },
                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            grid: {
                x: 50,
                y:20,
                x2:22,
                y2:40,
                borderWidth: 0
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    name:'省份',
                    data:areaname,
                    splitLine: {
                        show: false
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#a4a7ab',
                            align: 'center'
                        }
                    }
                }
            ],
            yAxis : [
                {
                    type : 'value',
                    name:'总数/车次',
                    splitLine: {
                        show: false
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#a4a7ab'
                        }
                    }
                }
            ],
            series : [
                {
                    name:'数量（辆）',
                    type:'bar',
                    /*barWidth:'30',*/
                    data:areavalue,
                    itemStyle: {
                        normal: {
                            label: {
                                show: true, //开启显示
                                position: 'top', //在上方显示
                                textStyle: { //数值样式
                                    color: 'white'
                                    /*fontSize: 16*/
                                }
                            },
                            color:"#1afffd"
                        }
                    }

                }
            ]
        };
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    })
}





